/*     */ package com.zimbra.qa.unittest.prov;
/*     */ 
/*     */ import com.google.common.collect.Maps;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.AutoProvAuthMech;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.AutoProvMode;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.ldap.AutoProvisionListener;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZMutableEntry;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.junit.Assert;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AutoProvisionTestUtil
/*     */ {
/*     */   public static class MarkEntryProvisionedListener
/*     */     implements AutoProvisionListener
/*     */   {
/*     */     private static final String PROVED_INDICATOR_ATTR = "zimbraNotes";
/*     */     private static final String PROVED_NOTE = "PROVISIONED IN ZIMBRA";
/*     */     public static final String NOT_PROVED_FILTER = "(!(zimbraNotes=PROVISIONED IN ZIMBRA))";
/*     */     
/*     */     public void postCreate(Domain domain, Account acct, String externalDN)
/*     */     {
/*  56 */       Map<String, Object> attrs = Maps.newHashMap();
/*  57 */       attrs.put("zimbraNotes", "PROVISIONED IN ZIMBRA");
/*     */       try {
/*  59 */         modifyExternalAcctEntry(externalDN, attrs);
/*     */       } catch (Exception e) {
/*  61 */         Assert.fail();
/*     */       }
/*     */     }
/*     */     
/*     */     private void modifyExternalAcctEntry(String externalDN, Map<String, Object> extAcctAttrs) throws Exception
/*     */     {
/*  67 */       ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UNITTEST);
/*     */       try {
/*  69 */         ZMutableEntry entry = LdapClient.createMutableEntry();
/*  70 */         entry.mapToAttrs(extAcctAttrs);
/*  71 */         zlc.replaceAttributes(externalDN, entry.getAttributes());
/*     */       } finally {
/*  73 */         LdapClient.closeContext(zlc);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public static Map<String, Object> commonZimbraDomainAttrs() {
/*  79 */     Map<String, Object> zimbraDomainAttrs = new HashMap();
/*     */     
/*  81 */     StringUtil.addToMultiMap(zimbraDomainAttrs, "zimbraAutoProvAuthMech", ZAttrProvisioning.AutoProvAuthMech.LDAP.name());
/*  82 */     StringUtil.addToMultiMap(zimbraDomainAttrs, "zimbraAutoProvMode", ZAttrProvisioning.AutoProvMode.LAZY.name());
/*  83 */     StringUtil.addToMultiMap(zimbraDomainAttrs, "zimbraAutoProvMode", ZAttrProvisioning.AutoProvMode.MANUAL.name());
/*  84 */     StringUtil.addToMultiMap(zimbraDomainAttrs, "zimbraAutoProvMode", ZAttrProvisioning.AutoProvMode.EAGER.name());
/*     */     
/*  86 */     zimbraDomainAttrs.put("zimbraAutoProvLdapURL", "ldap://localhost:389");
/*  87 */     zimbraDomainAttrs.put("zimbraAutoProvLdapAdminBindDn", "cn=config");
/*  88 */     zimbraDomainAttrs.put("zimbraAutoProvLdapAdminBindPassword", "zimbra");
/*     */     
/*  90 */     StringUtil.addToMultiMap(zimbraDomainAttrs, "zimbraAutoProvAttrMap", "sn=displayName");
/*  91 */     StringUtil.addToMultiMap(zimbraDomainAttrs, "zimbraAutoProvAttrMap", "displayName=sn");
/*     */     
/*  93 */     return zimbraDomainAttrs;
/*     */   }
/*     */   
/*     */   public static void verifyAcctAutoProvisioned(Account acct) throws Exception {
/*  97 */     verifyAcctAutoProvisioned(acct, null);
/*     */   }
/*     */   
/*     */   public static void verifyAcctAutoProvisioned(Account acct, String expectedAcctName) throws Exception
/*     */   {
/* 102 */     Assert.assertNotNull(acct);
/* 103 */     if (expectedAcctName != null) {
/* 104 */       Assert.assertEquals(expectedAcctName, acct.getName());
/*     */     }
/* 106 */     verifyAttrMapping(acct);
/*     */   }
/*     */   
/*     */   static void verifyAttrMapping(Account acct) throws Exception {
/* 110 */     Assert.assertEquals("last name", acct.getAttr("displayName"));
/* 111 */     Assert.assertEquals("display name", acct.getAttr("sn"));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/AutoProvisionTestUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */